package eu.jpereira.trainings.designpatterns.structural.decorator.channel.decorator;

import eu.jpereira.trainings.designpatterns.structural.decorator.channel.SocialChannel;

public class WordCensor extends SocialChannelDecorator {

	private String string;
	
	public WordCensor(String string)
	{
		this.string = string;
	}
	
	public WordCensor(String string, SocialChannel channel){
		this.string = string;
		this.delegate = channel;
	}
	
	@Override
	public void deliverMessage(String message) {
		if(message.toLowerCase().contains(this.string.toLowerCase())){
			StringBuilder builder = new StringBuilder();
			builder.append(message.replace(this.string, "###"));
			message = builder.toString();
		}
		delegate.deliverMessage(message);
		
	}

}
